package cn.itcast.manager.serviceimpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.itcast.manager.service.UserService;
import cn.itcast.usermanager.mapper.NewUserMapper;
import cn.itcast.usermanager.mapper.UserMapper;
import cn.itcast.usermanager.pojo.EasyUIResult;
import cn.itcast.usermanager.pojo.User;
@Service
public class UserServiceImpl implements UserService {
	@Autowired
	private UserMapper userMapper;
	
	@Autowired
	private NewUserMapper newUserMapper;
	
	@Override
	public EasyUIResult queryPage(Integer pageNum,Integer pageSize) {
		//在查新方法前调用分页组件代码
		PageHelper.startPage(pageNum, pageSize);
		
//		List<User> userList = this.userMapper.queryUesrPage((pageNum-1)*pageSize, pageSize);
		List<User> userList = this.userMapper.queryAll();
		PageInfo<User> pageInfo = new PageInfo<>(userList);
		
		EasyUIResult result = new EasyUIResult();
		result.setTotal(pageInfo.getTotal());
		result.setRows(pageInfo.getList());
		
		return result;
	}

	@Override
	public void insertUser(User user1, User user2) {

		this.userMapper.insertUser(user1);
//		int i = 1/0; 
		this.userMapper.insertUser(user2);


		
	}

	@Override
	public Boolean addUser(User user) {
		int count = this.userMapper.insertUser(user);
		if (count>0) {
			return true;
		}
		return false;
	}

	@Override
	public Boolean deleteUser(String[] ids) {
		int index = this.userMapper.deleteUser(ids);
		
		if (index > 0) {
			return true;
		}
		
		return false;		
	}

	@Override
	public Boolean updateUser(User user) {
		int i = this.newUserMapper.updateByPrimaryKeySelective(user);
		if (i>0) {
			return true;
		}		
			return false;

	}

	
	
	
	

}
